home *** CD-ROM | disk | FTP | other *** search
- /*
- * playSound -- XFCN to play a sound
- *
- * callout("XFCN", "PlaySound", "Sound")
- *
- * where "Sound" is the name of a resource of type 'snd '.
- *
- * The caller should make sure that the resource fork that
- * contains the desired sound is open.
- */
-
- #include <SetupA4.h>
- #include <SoundMgr.h>
- #include "IconXCmd.h"
-
-
- #define NIL 0x00000000
-
- pascal void main(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- SndChannelPtr tempChan, theChan;
- Handle hSnd;
- OSErr err;
- Handle h;
-
- RememberA0(); /* set up for globals */
- SetUpA4();
-
- /* check parameters */
- if (paramPtr->paramCount != 1) {
- paramPtr->returnValue = (Handle)NewString("\pNeed one parameter in PlaySound XFCN");
- PtoCstr(*(paramPtr->returnValue));
- RestoreA4();
- return;
- }
-
- /* Lock parameter, convert to a Pascal string */
- h = paramPtr->params[0];
- HLock(h);
- CtoPstr(*h);
- hSnd = GetNamedResource( (ResType)'snd ', *h );
- HUnlock(h);
-
- if (!hSnd) {
- paramPtr->returnValue = (Handle)NewString("\pNo such sound in PlaySound XFCN");
- PtoCstr(*(paramPtr->returnValue));
- RestoreA4();
- return;
- }
-
- tempChan = NIL; /* open new channel */
- err = SndNewChannel(&tempChan, 0, 0L, NIL);
- if (err) {
- paramPtr->returnValue = (Handle)NewString("\pChannel opening error in PlaySound XFCN");
- PtoCstr(*(paramPtr->returnValue));
- ReleaseResource(hSnd); /* release resource */
- RestoreA4();
- return;
- }
-
- /* If a sound channel was already open, nextChan will have a pointer to it
- * in tempChan->nextChan; if not nextChan will contain NIL.
- */
-
- theChan = tempChan->nextChan; /* get pointer to open channel, if any */
- err = SndDisposeChannel(tempChan, FALSE); /* close ours */
-
- /* Play the sound. If a channel was open, it will be used. If not, theChan will
- * be NIL and SndPlay will create a temporary channel.
- */
- HLock(hSnd);
- err = SndPlay(theChan, hSnd, FALSE); /* play sound */
- HUnlock(hSnd);
- ReleaseResource(hSnd);
-
- RestoreA4();
- }
-
-